package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.PartGroup;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.PartGroupService;

/**
 * To achieve the partGroup to add, delete, update and query
 * 
 * @author wj
 * @Date 2020/4/1
 */
@Controller
@RequestMapping(value = "/partGroup")
public class PartGroupController {
	
	@Autowired
	private PartGroupService partGroupService;
	
	@RequestMapping(value = "/operateByPartGroup")
	public @ResponseBody ResultBean operateByPartGroup(@RequestBody PartGroup partGroup) {
		ResultBean resultBean = new ResultBean(true,' ');
		// Judge to add
		if (partGroup.getModificationFlag()== IModificationFlags.NEW) {
			return partGroupService.save(partGroup);
		// Judge to update
		} else if (partGroup.getModificationFlag() == IModificationFlags.MODIFIED) {
			return partGroupService.update(partGroup);
		// Judge to delete
		} else if (partGroup.getModificationFlag() == IModificationFlags.DELETED) {
			return partGroupService.delete(partGroup);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/deleteAll")
	public @ResponseBody ResultBean deleteAll(@RequestBody PartGroup partGroup) {
		return partGroupService.deleteAll(partGroup);
	}

}
